package b_workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;
import utils.RabbitMQUtils;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 雷哥
 * @Date: 2020/10/06/22:51
 * @Description:生产者
 *
 */
public class Producer {

  @Test
  public void sendMessage() throws  Exception{
    Connection connection = RabbitMQUtils.getConnection();
    //创建信道
    Channel channel = connection.createChannel();
    //声明队列
    channel.queueDeclare("hello",false,false,false,null);
    //发送消息  发100条
    for (int i = 1; i <=10 ; i++) {
      channel.basicPublish("","hello",null,("hello rabbitmq---workqueue"+i).getBytes());
    }
    //关闭
    RabbitMQUtils.closeChannelAndConnection(channel,connection);
    System.out.println("消息发送成功");
  }

}
